#include "ExampleModuleI.h"
#include "orbsvcs/CosNamingC.h"
#include "ExampleModuleC.h"
#include <CORBA.h>
#include <iostream>

int main(int argc, char* argv[]) {
    try {
        CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
        CORBA::Object_var naming_context_obj = orb->resolve_initial_references("NameService");
        CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow(naming_context_obj);

        CosNaming::Name name;
        name.length(1);
        name[0].id = CORBA::string_dup("ExampleGroup");

        CORBA::Object_var example_group_obj = naming_context->resolve(name);
        ExampleModule::Example_var example_group = ExampleModule::Example::_narrow(example_group_obj);

        if (!CORBA::is_nil(example_group)) {
            example_group->say_hello();
        } else {
            std::cerr << "Object reference is nil" << std::endl;
        }

        orb->destroy();
    } catch (const CORBA::Exception& ex) {
        std::cerr << "CORBA exception: " << ex << std::endl;
    }
    return 0;
}
